Ext.define('pm.view.Project.List' ,{
    extend: 'Ext.grid.Panel',
    alias : 'widget.ProjectsList',

    store: 'Projects',
    trackMouse: true,
    
    viewConfig: {
        plugins: {
            ddGroup: 'GridExample2',
            ptype: 'gridviewdragdrop',
        },
    },

    columns: [
        {header: 'Name',  dataIndex: 'name',  flex: 2},
        {header: 'Description', dataIndex: 'desc', flex: 3},
        {header: 'Description', dataIndex: 'personal', flex: 3},
    ],

    listeners: {
        render: function(v) {
            this.getView().on('beforedrop', function(node, data, dropRec, dropPosition) {
                if(data.records.length) {
                    return v.dragItemToTarget(data.records[0], dropRec)
                }
                return false
            })
        },
    },

    dragItemToTarget: function(item, target) {
        console.log('drag ' + item.get('name') + ' on ' + target.get('name') + ', dropped class=' + item.self.getName())

        if(item.self.getName() == 'pm.model.Project') {
            return true
        } else if(item.self.getName() == 'pm.model.Personal') {
            this.fireEvent('addUserToProject', item, target)
            return false
        }
    },

    initComponent: function() {

        this.tooltip = Ext.create('Ext.tip.ToolTip', {})

        this.callParent(arguments);
    },

    showToolTip: function(record, e) {
        var tip = this.tooltip
        tip.show()
        tip.setPosition(e.getXY())
        var txt = ''
        tip.update('Over company "' + txt + '"');
    }

});